using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace QFramework.Monk
{
    public class GameEntityObj : ViewController
    {
        protected Collider2D[] mChildrenCollider2Ds;

        public bool mIsInScreen;
        private void Awake()
        {
            mChildrenCollider2Ds = GetComponentsInChildren<Collider2D>();
        }

        private void OnBecameInvisible()
        {
            ToggleColliders(false);
            mIsInScreen = false;
        }

        private void OnBecameVisible()
        {
            ToggleColliders(true);
            mIsInScreen = true;
        }

        private void ToggleColliders(bool enable)
        {

            if (mChildrenCollider2Ds != null)
            {
                foreach (var collider2D in mChildrenCollider2Ds)
                {
                    collider2D.enabled = enable;
                }
            }
        }
    }
}